package com.atguigu.cloud.controller;

import com.atguigu.cloud.entities.Pay;
import com.atguigu.cloud.entities.PayDTO;
import com.atguigu.cloud.resp.ResultData;
import com.atguigu.cloud.service.PayService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Slf4j
@Tag(name = "支付微服务模块",description = "支付CRUD")
public class PayController {
    @Resource
    private PayService payService;
    @PostMapping(value = "/pay/add")
    @Operation(summary = "新增",description = "新增支付流水方法，json做参数")
    public ResultData<String> addPay(@RequestBody Pay pay){
        System.out.println(pay.toString());
        int i =payService.add(pay);
        return ResultData.seccess("插入成功");
    }
    @DeleteMapping(value = "/pay/del/{id}")
    @Operation(summary = "删除",description = "删除支付流水方法，json做参数")
    public ResultData<String> deletePay(@PathVariable("id") Integer id){
        int i =payService.delete(id);
        return ResultData.seccess("删除成功");
    }
    @PutMapping(value = "/pay/update")
    @Operation(summary = "更新",description = "更新支付流水方法，json做参数")
    public ResultData<String> updatePay(@RequestBody PayDTO payDTO){
        Pay pay =new Pay();
        BeanUtils.copyProperties(payDTO,pay);
        int i =payService.update(pay);
        return ResultData.seccess("更新成功");
    }
    @GetMapping(value = "/pay/get/{id}")
    @Operation(summary = "查询",description = "根据id查询支付流水方法，json做参数")
    public ResultData<Pay> getById(@PathVariable("id") Integer id){
        if(id==-4) throw new RuntimeException("id不能为负数");
        return ResultData.seccess(payService.getById(id));
    }
    @GetMapping(value = "/pay/get/list")
    @Operation(summary = "查询全部",description = "查询全部支付流水方法，json做参数")
    public ResultData<List<Pay>> getlist(){
        return ResultData.seccess(payService.getAll());
    }
}
